<?php

class Home extends CI_Controller {
	
	function login() {
		$is_logged_in = $this->session->userdata('logged_in');
		if(!isset($is_logged_in) || $is_logged_in != true) {
			$data['title'] = 'Welcome to DepEd UIS Dashboard';
			$data['status'] = 2;
			$data['view'] = 'home/login';
			$this->load->view('template', $data);
		}
		else {
			redirect('home/dashboard');
		}
	}
	
	//ebeis
	function ebeis (){
		$data['title'] = 'Enhanced Basic Education Information System';
		$data['view'] = 'home/ebeis';
		$this->load->view('template', $data);
	}
	
	//ebeis
	function ebeis2 (){
		$data['title'] = 'Enhanced Basic Education Information System';
		$data['view'] = 'home/ebeis2';
		$this->load->view('template', $data);
	}
	
	//ebeis
	function ebeis3 (){
		$data['title'] = 'Enhanced Basic Education Information System';
		$data['view'] = 'home/ebeis3';
		$this->load->view('template', $data);
	}
	function school_profile () {
	
		
		$data['title'] = 'Government Elementary School Profile';
		$data['view'] = 'home/school_profile';
		$this->load->view('template', $data);
	
	}
	
	function school_profile2 () {
	
		
		$data['title'] = 'Government Elementary School Profile';
		$data['view'] = 'home/school_profile2';
		$this->load->view('template', $data);
	
	}
	
	
	
	
	function login_error() {
		$data['title'] = 'Welcome to DepEd UIS Dashboard';
		$data['status'] = 0;
		$data['view'] = 'home/login';
		$this->load->view('template', $data);
	}
	
	function logout() {
		$this->session->sess_destroy();
		redirect('home/login');
	}
	
	function dashboard() {
		$data['title'] = 'Dashboard';
		$data['view'] = 'home/index';
		$this->load->view('template', $data);
	}
	
	function validate_credentials() {
		$username = $this->input->post('username');
		$valid_users = array(
			'jdelacruz',
			'mcastro',
			'rsantos'
		);
		$users_info = array(
			'jdelacruz' => 'secretary',
			'mcastro' => 'region head',
			'rsantos' => 'school head'
		);
		if(in_array($username, $valid_users)) {
			$data = array(
				'username' => $this->input->post('username'),
				'user_type' => $users_info[$username],
				'logged_in' => true
			);
			$this->session->set_userdata($data);
			
			redirect('home/dashboard');
		}
		
		//invalid username or password
		else {
			redirect('home/login_error');
		}
	}
}